import axios from 'axios'
// import store from '@/store'
// import { getToken } from '@/utils/auth'

// 创建实例
const service = axios.create({
  baseURL: 'http://amall-api.unmcc.com',
  timeout: 15000 * 999,
  validateStatus: status => {
    return status < 600
  },
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
    // 'Content-Type': 'application/ x-www-form-urlencoded;charset=utf-8'
  }
})

// 请求拦截器
service.interceptors.request.use(
  config => {
    config.data = JSON.stringify(config.data)
    if (config.data) {
      console.log(config.data)
    }
    // const token = getToken()
    const token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJhdWQiOiIiLCJpYXQiOjE1NzQwNjkzMjgsIm5iZiI6MTU3NDA2OTMyOCwiZXhwIjoxODg5NDI5MzI4LCJ1aWQiOjIyMX0.S5sOJsjKHreTcmAGPJFzc6kotrzsUhl8L_Pe3ZD5sDQ'
    if (token) {
      config.headers['authorization'] = `Bearer ${token}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  response => {
    const { data } = response

    console.log('request-log: ', response.config.url, data)

    return data
  },
  error => {
    return Promise.reject(error)
  }
)

export default service
